<#include "common.ftl">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<!--功能描述：
            创建人：
            创建时间：${createdate}
            修改人：
            修改时间：${createdate}
            修改备注：
    @version 1.0.0
  -->
<sqlMap namespace="${beanName}">
    <typeAlias alias="${beanObject}" type="${beanPackage}.${beanName}" />
    <resultMap id="${entityBean.javaName}Result" class="${beanObject}">
<#list columnBeanList as columnBean>
       <result property="${columnBean.property}" column="${columnBean.column}" />
</#list>
    </resultMap>
    <!-- 查询的基本条件(可添加其他的参数) -->
    <sql id="${beanName}_base">
        <dynamic prepend="WHERE">
<#list columnBeanList as columnBean>
            <isNotEmpty property="${columnBean.property}" prepend="AND">
                T.${columnBean.column?upper_case} = #${columnBean.property}#
            </isNotEmpty>
</#list>
        </dynamic>
    </sql>
    <!-- 查询 -->
    <select id="select" parameterClass="${beanObject}" resultMap="${entityBean.javaName}Result">
        SELECT
<#list columnBeanList as columnBean>
            T.${columnBean.column}<#if columnBean_has_next>,</#if>
</#list>
        FROM ${entityBean.tableName} T
        <isParameterPresent>
            <include refid="${beanName}_base"/>
        </isParameterPresent>
    </select>
    <!--根据id查询对象(可传入其他参数) author：  -->
    <select id="selectObject" parameterClass="${beanObject}" resultMap="${entityBean.javaName}Result">
        SELECT
<#list columnBeanList as columnBean>
            T.${columnBean.column?upper_case}<#if columnBean_has_next>,</#if>
</#list>
            FROM ${entityBean.tableName} T WHERE
<#list columnBeanList as columnBean>
<#if columnBean.isPrimaryKey>
            T.${columnBean.column?upper_case} = #${columnBean.property}#
</#if>
</#list>
    </select>
    <!-- 插入 -->
    <insert id="insert" parameterClass="${beanObject}">
        INSERT INTO ${entityBean.tableName}(
            <dynamic prepend=" ">
<#list columnBeanList as columnBean>
                <isNotNull property="${columnBean.property}" prepend=",">
                    ${columnBean.column?upper_case}
                </isNotNull>
</#list>
            </dynamic>
        ) values (
            <dynamic prepend=" ">
<#list columnBeanList as columnBean>
                <isNotNull property="${columnBean.property}" prepend=",">
                    #${columnBean.property}#
                </isNotNull>
</#list>
            </dynamic>
        )
    </insert>
    <!-- 更新 -->
    <update id="update" parameterClass="${beanObject}">
        UPDATE ${entityBean.tableName} T
        <dynamic prepend="SET">
<#list columnBeanList as columnBean>
            <isNotEmpty property="${columnBean.property}" prepend=",">
                T.${columnBean.column?upper_case} = #${columnBean.property}#
            </isNotEmpty>
</#list>
        </dynamic>
        <dynamic prepend="WHERE">
<#list columnBeanList as columnBean>
<#if columnBean.isPrimaryKey>
            <isNotEmpty property="${columnBean.property}" prepend="AND">
                T.${columnBean.column?upper_case} = #${columnBean.property}#
            </isNotEmpty>
</#if>
</#list>
        </dynamic>
    </update>
    <!--根据条件删除对象 author： -->
    <delete id="deleteObject" parameterClass="${beanObject}">
        DELETE FROM ${entityBean.tableName} T WHERE
        <dynamic prepend=" ">
<#list columnBeanList as columnBean>
<#if columnBean.isPrimaryKey>
            <isNotEmpty property="${columnBean.property}" prepend="AND">
                T.${columnBean.column?upper_case} = #${columnBean.property}#
            </isNotEmpty>
</#if>
</#list>
        </dynamic>
    </delete>
    <!-- 记录总条数  author：  -->
    <select id="count" resultClass="int" parameterClass="${beanObject}">
        SELECT COUNT(1) FROM ${entityBean.tableName}
        <isParameterPresent>
            <include refid="${beanName}_base" />
        </isParameterPresent>
    </select>
    <!-- 分页显示接入方列表  author：-->
    <select id="query" resultMap="${entityBean.javaName}Result" parameterClass="${beanObject}" remapResults="true">
        <isNotEmpty property="startIndex">
            <include refid="Common.selectPageStart"/>
        </isNotEmpty>
        SELECT
<#list columnBeanList as columnBean>
            ${columnBean.column}<#if columnBean_has_next>,</#if>
</#list>
        FROM ${entityBean.tableName} T
        <include refid="${beanName}_base" />
        <!-- add order by -->
        <isNotEmpty property="startIndex">
            <include refid="Common.selectPageEnd"/>
        </isNotEmpty>
    </select>
</sqlMap>